package chess;

import java.util.ArrayList;
import java.util.Arrays;

import junit.framework.Assert;


public final class MyAsserts {
	@SuppressWarnings("rawtypes")
	public static void assertArrayArrayListEquals(ArrayList expected, ArrayList actual)
	{
		assertArrayArrayListEquals("", expected, actual);
	}
	
	@SuppressWarnings("rawtypes")
	public static void assertArrayArrayListEquals(String message, ArrayList expected, ArrayList actual)
	{
		if (expected.size() != actual.size()) {
			failEquals(message, ArrayArrayListToString(expected), ArrayArrayListToString(actual));
		}
		
		for (int i = 0; i < expected.size(); i++) {
			if (!Arrays.equals((Object[]) expected.get(i), (Object[]) actual.get(i))) {
				failEquals(message +
							"expected element " + java.util.Arrays.deepToString((Object[]) expected.get(i)) + " != " +
							java.util.Arrays.deepToString((Object[]) actual.get(i)) + "\n",
						ArrayArrayListToString(expected),
						ArrayArrayListToString(actual));
			}
		}
	}
	
	private static void failEquals(
		String message, String expected, String actual) {
		
		String actualDesc = (actual == null) ? "null" : ('<' + actual + '>');
		failWithMessage(message, "Expected vs. Actual\n\t<" + expected
				+ ">\n\t" + actualDesc);
	}

	private static void failWithMessage(String userMessage, String ourMessage) {
		Assert.fail((userMessage == null)
				? ourMessage
				: userMessage + ' ' + ourMessage);
	}

	@SuppressWarnings("rawtypes")
	private static String ArrayArrayListToString(ArrayList value){
		String message = "";
		
		for (int i = 0; i < value.size(); i++) {
			message += java.util.Arrays.deepToString((Object[]) value.get(i)) + (i==value.size()-1 ? "" : ", ");
		}
		
		return message;
	}
}
